/*     */ package com.zimbra.cs.dav.resource;
/*     */ 
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMailbox.Options;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.localconfig.DebugConfig;
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.service.ServiceException.Argument;
/*     */ import com.zimbra.common.soap.SoapFaultException;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.dav.DavContext;
/*     */ import com.zimbra.cs.dav.DavContext.RequestProp;
/*     */ import com.zimbra.cs.dav.DavElements;
/*     */ import com.zimbra.cs.dav.DavException;
/*     */ import com.zimbra.cs.dav.DavException.CannotModifyProtectedProperty;
/*     */ import com.zimbra.cs.dav.property.Acl;
/*     */ import com.zimbra.cs.dav.property.Acl.Ace;
/*     */ import com.zimbra.cs.dav.property.CalDavProperty.CalComponent;
/*     */ import com.zimbra.cs.dav.property.ResourceProperty;
/*     */ import com.zimbra.cs.mailbox.ACL;
/*     */ import com.zimbra.cs.mailbox.ACL.Grant;
/*     */ import com.zimbra.cs.mailbox.Contact;
/*     */ import com.zimbra.cs.mailbox.DavNames;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailServiceException;
/*     */ import com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxLock;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.Metadata;
/*     */ import com.zimbra.cs.service.AuthProvider;
/*     */ import com.zimbra.cs.service.formatter.VCard;
/*     */ import com.zimbra.cs.service.mail.ItemActionHelper;
/*     */ import com.zimbra.cs.service.util.ItemId;
/*     */ import com.zimbra.cs.util.AccountUtil;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.ByteArrayOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collections;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import org.dom4j.Attribute;
/*     */ import org.dom4j.Document;
/*     */ import org.dom4j.DocumentException;
/*     */ import org.dom4j.DocumentHelper;
/*     */ import org.dom4j.QName;
/*     */ import org.dom4j.io.OutputFormat;
/*     */ import org.dom4j.io.SAXReader;
/*     */ import org.dom4j.io.XMLWriter;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public abstract class MailItemResource
/*     */   extends DavResource
/*     */ {
/*     */   protected int mFolderId;
/*     */   protected int mId;
/*     */   protected MailItem.Type type;
/*     */   protected Color mColor;
/*     */   protected String mEtag;
/*     */   protected String mSubject;
/*     */   protected String mPath;
/*     */   protected long mModifiedDate;
/*     */   protected String mOwnerId;
/*     */   protected Map<QName, org.dom4j.Element> mDeadProps;
/*     */   private static final String CONFIG_KEY = "caldav";
/*     */   private static final int PROP_LENGTH_LIMIT = 1024;
/*     */   private static final String BLUE = "#0252D4FF";
/*     */   private static final String CYAN = "#008284FF";
/*     */   private static final String GRAY = "#848284FF";
/*     */   private static final String GREEN = "#2CA10BFF";
/*     */   private static final String ORANGE = "#F57802FF";
/*     */   private static final String PINK = "#B027AEFF";
/*     */   private static final String PURPLE = "#492BA1FF";
/*     */   private static final String RED = "#E51717FF";
/*     */   private static final String YELLOW = "#848200FF";
/*     */   private static final String DEFAULT_COLOR = "#F57802FF";
/* 108 */   protected static final String[] COLOR_MAP = { "#F57802FF", "#0252D4FF", "#008284FF", "#2CA10BFF", "#492BA1FF", "#E51717FF", "#848200FF", "#B027AEFF", "#848284FF", "#F57802FF" };
/*     */   
/*     */ 
/*     */ 
/* 112 */   protected static final ArrayList<String> COLOR_LIST = new ArrayList();
/*     */   
/*     */   static {
/* 115 */     Collections.addAll(COLOR_LIST, COLOR_MAP);
/*     */   }
/*     */   
/*     */   public MailItemResource(DavContext ctxt, MailItem item) throws ServiceException {
/* 119 */     this(ctxt, getItemPath(ctxt, item), item);
/*     */   }
/*     */   
/*     */   public MailItemResource(DavContext ctxt, String path, MailItem item) throws ServiceException {
/* 123 */     super(path, ctxt.getUser());
/* 124 */     this.mFolderId = item.getFolderId();
/* 125 */     this.mId = item.getId();
/* 126 */     this.type = item.getType();
/* 127 */     this.mEtag = getEtag(item);
/* 128 */     this.mSubject = item.getSubject();
/* 129 */     this.mPath = item.getPath();
/* 130 */     this.mModifiedDate = item.getChangeDate();
/* 131 */     this.mOwnerId = item.getAccount().getId();
/*     */     try {
/* 133 */       this.mDeadProps = getDeadProps(ctxt, item);
/*     */     } catch (Exception e) {
/* 135 */       ZimbraLog.dav.warn("can't get dead properties for MailItem id=" + this.mId, e);
/*     */     }
/* 137 */     setProperty("getetag", this.mEtag);
/* 138 */     if (this.mModifiedDate > 0L)
/* 139 */       setLastModifiedDate(this.mModifiedDate);
/* 140 */     this.mColor = item.getRgbColor();
/* 141 */     setProperty(DavElements.E_DISPLAYNAME, item.getName());
/* 142 */     addProperty(Acl.getPrincipalUrl(this));
/*     */   }
/*     */   
/*     */   public MailItemResource(String path, String acct) {
/* 146 */     super(path, acct);
/* 147 */     this.mDeadProps = new HashMap();
/*     */     try {
/* 149 */       Account account = Provisioning.getInstance().getAccountByName(acct);
/* 150 */       if (account != null) {
/* 151 */         this.mOwnerId = account.getId();
/*     */       }
/*     */     }
/*     */     catch (ServiceException ignore) {}
/*     */   }
/*     */   
/*     */   private static String getItemPath(DavContext ctxt, MailItem item) {
/* 158 */     String path = ctxt.getCollectionPath();
/* 159 */     if (path != null) {
/* 160 */       if (!path.endsWith("/"))
/* 161 */         path = path + "/";
/* 162 */       path = path + item.getName();
/*     */     } else {
/* 164 */       path = ctxt.getPath();
/*     */     }
/* 166 */     if (((item.getType() == MailItem.Type.CONTACT) || (item.getType() == MailItem.Type.FOLDER) || (item.getType() == MailItem.Type.MOUNTPOINT)) && (!path.endsWith("/")))
/*     */     {
/* 168 */       path = path + "/";
/*     */     }
/* 170 */     if (item.getType() == MailItem.Type.CONTACT) {
/* 171 */       path = path + VCard.getUrl((Contact)item) + ".vcf";
/*     */     }
/* 173 */     return path;
/*     */   }
/*     */   
/*     */   public boolean hasEtag()
/*     */   {
/* 178 */     return true;
/*     */   }
/*     */   
/*     */   public String getEtag()
/*     */   {
/* 183 */     return this.mEtag;
/*     */   }
/*     */   
/*     */   public String getName()
/*     */   {
/* 188 */     return this.mSubject;
/*     */   }
/*     */   
/*     */   protected Mailbox getMailbox(DavContext ctxt) throws ServiceException, DavException {
/* 192 */     Provisioning prov = Provisioning.getInstance();
/* 193 */     Account account = prov.get(Key.AccountBy.id, this.mOwnerId);
/* 194 */     if (account == null)
/* 195 */       throw new DavException("no such account " + this.mOwnerId, 404, null);
/* 196 */     return MailboxManager.getInstance().getMailboxByAccount(account);
/*     */   }
/*     */   
/*     */   protected MailItem getMailItem(DavContext ctxt) throws ServiceException, DavException {
/* 200 */     Mailbox mbox = getMailbox(ctxt);
/* 201 */     return mbox.getItemById(ctxt.getOperationContext(), this.mId, MailItem.Type.UNKNOWN);
/*     */   }
/*     */   
/*     */   public void delete(DavContext ctxt)
/*     */     throws DavException
/*     */   {
/* 207 */     if (this.mId == 0) {
/* 208 */       throw new DavException("cannot delete resource", 403, null);
/*     */     }
/*     */     try {
/* 211 */       Mailbox mbox = getMailbox(ctxt);
/* 212 */       if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
/* 213 */         DavNames.remove(mbox.getId(), this.mId);
/*     */       }
/*     */       
/* 216 */       if (getMailItem(ctxt).inTrash()) {
/* 217 */         hardDelete(ctxt);
/* 218 */         return;
/*     */       }
/* 220 */       mbox.move(ctxt.getOperationContext(), this.mId, MailItem.Type.UNKNOWN, 3);
/*     */     } catch (ServiceException se) {
/* 222 */       if (se.getCode().equals("mail.ALREADY_EXISTS")) {
/* 223 */         hardDelete(ctxt);
/* 224 */         return;
/*     */       }
/* 226 */       int resCode = (se instanceof MailServiceException.NoSuchItemException) ? 404 : 403;
/*     */       
/* 228 */       throw new DavException("cannot delete item", resCode, se);
/*     */     }
/*     */   }
/*     */   
/*     */   public void hardDelete(DavContext ctxt) throws DavException
/*     */   {
/* 234 */     if (this.mId == 0)
/* 235 */       throw new DavException("cannot hard delete resource", 403, null);
/*     */     try {
/* 237 */       Mailbox mbox = getMailbox(ctxt);
/* 238 */       mbox.delete(ctxt.getOperationContext(), this.mId, MailItem.Type.UNKNOWN);
/*     */     } catch (ServiceException se) {
/* 240 */       int resCode = (se instanceof MailServiceException.NoSuchItemException) ? 404 : 403;
/*     */       
/* 242 */       throw new DavException("cannot delete item", resCode, se);
/*     */     }
/*     */   }
/*     */   
/*     */   private static ZMailbox getZMailbox(DavContext ctxt, Collection col) throws ServiceException {
/* 247 */     AuthToken authToken = AuthProvider.getAuthToken(ctxt.getAuthAccount());
/* 248 */     Account acct = Provisioning.getInstance().getAccountById(col.getItemId().getAccountId());
/* 249 */     ZMailbox.Options zoptions = new ZMailbox.Options(authToken.toZAuthToken(), AccountUtil.getSoapUri(acct));
/* 250 */     zoptions.setNoSession(true);
/* 251 */     zoptions.setTargetAccount(acct.getId());
/* 252 */     zoptions.setTargetAccountBy(Key.AccountBy.id);
/* 253 */     return ZMailbox.getMailbox(zoptions);
/*     */   }
/*     */   
/* 256 */   private void deleteDestinationItem(DavContext ctxt, Collection dest, int id) throws ServiceException, DavException { Mailbox mbox = getMailbox(ctxt);
/* 257 */     if (dest.getItemId().belongsTo(mbox)) {
/* 258 */       mbox.delete(ctxt.getOperationContext(), id, MailItem.Type.UNKNOWN, null);
/*     */     } else {
/* 260 */       ZMailbox zmbx = getZMailbox(ctxt, dest);
/* 261 */       ItemId itemId = new ItemId(dest.getItemId().getAccountId(), id);
/* 262 */       zmbx.deleteItem(itemId.toString(), null);
/*     */     }
/*     */   }
/*     */   
/*     */   public void move(DavContext ctxt, Collection dest, String newName) throws DavException
/*     */   {
/*     */     try {
/* 269 */       Mailbox mbox = getMailbox(ctxt);
/* 270 */       ArrayList<Integer> ids = new ArrayList();
/* 271 */       ids.add(Integer.valueOf(this.mId));
/* 272 */       if (newName != null) {
/* 273 */         ItemActionHelper.RENAME(ctxt.getOperationContext(), mbox, SoapProtocol.Soap12, ids, this.type, null, newName, dest.getItemId());
/*     */       } else
/* 275 */         ItemActionHelper.MOVE(ctxt.getOperationContext(), mbox, SoapProtocol.Soap12, ids, this.type, null, dest.getItemId());
/*     */     } catch (ServiceException se) {
/* 277 */       int resCode = (se instanceof MailServiceException.NoSuchItemException) ? 404 : 403;
/*     */       
/* 279 */       if (se.getCode().equals("mail.ALREADY_EXISTS"))
/* 280 */         resCode = 412;
/* 281 */       throw new DavException("cannot move item", resCode, se);
/*     */     }
/*     */   }
/*     */   
/*     */   public void moveORcopyWithOverwrite(DavContext ctxt, Collection dest, String newName, boolean deleteOriginal) throws DavException {
/*     */     try {
/* 287 */       if (deleteOriginal) {
/* 288 */         move(ctxt, dest, newName);
/*     */       } else
/* 290 */         copy(ctxt, dest, newName);
/*     */     } catch (DavException e) {
/* 292 */       if (e.getStatus() == 412)
/*     */       {
/*     */ 
/*     */ 
/* 296 */         ServiceException se = (ServiceException)e.getCause();
/* 297 */         int id = 0;
/*     */         try {
/* 299 */           if (!se.getCode().equals("mail.ALREADY_EXISTS")) {
/* 300 */             throw e;
/*     */           }
/* 302 */           if ((se instanceof SoapFaultException)) {
/* 303 */             String itemIdStr = ((SoapFaultException)se).getArgumentValue("id");
/* 304 */             ItemId itemId = new ItemId(itemIdStr, dest.getItemId().getAccountId());
/* 305 */             id = itemId.getId();
/*     */           } else {
/* 307 */             String name = null;
/* 308 */             for (ServiceException.Argument arg : se.getArgs()) {
/* 309 */               if ((arg.name != null) && (arg.value != null) && (arg.value.length() > 0) && 
/* 310 */                 (arg.name.equals("name"))) {
/* 311 */                 name = arg.value;
/*     */               }
/*     */             }
/*     */             
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 321 */             if (id <= 0) {
/* 322 */               if ((name == null) && (!deleteOriginal))
/*     */               {
/* 324 */                 name = ctxt.getItem();
/*     */               }
/* 326 */               if (name != null) {
/* 327 */                 Mailbox mbox = getMailbox(ctxt);
/* 328 */                 MailItem item = mbox.getItemByPath(ctxt.getOperationContext(), name, dest.getId());
/* 329 */                 id = item.getId();
/*     */               } else {
/* 331 */                 throw e;
/*     */               }
/*     */             }
/*     */           }
/* 335 */           deleteDestinationItem(ctxt, dest, id);
/*     */         } catch (ServiceException se1) {
/* 337 */           throw new DavException("cannot move/copy item", 403, se1);
/*     */         }
/* 339 */         if (deleteOriginal) {
/* 340 */           move(ctxt, dest, newName);
/*     */         } else
/* 342 */           copy(ctxt, dest, newName);
/*     */       } else {
/* 344 */         throw e;
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void copy(DavContext ctxt, Collection dest, String newName) throws DavException
/*     */   {
/*     */     try {
/* 352 */       Mailbox mbox = getMailbox(ctxt);
/* 353 */       ArrayList<Integer> ids = new ArrayList();
/* 354 */       if (newName == null) {
/* 355 */         ids.add(Integer.valueOf(this.mId));
/* 356 */         ItemActionHelper.COPY(ctxt.getOperationContext(), mbox, SoapProtocol.Soap12, ids, this.type, null, dest.getItemId());
/*     */       }
/*     */       else {
/* 359 */         throw MailServiceException.CANNOT_COPY(this.mId);
/*     */       }
/*     */     } catch (ServiceException se) {
/* 362 */       int resCode = (se instanceof MailServiceException.NoSuchItemException) ? 404 : 403;
/*     */       
/* 364 */       if (se.getCode().equals("mail.ALREADY_EXISTS"))
/* 365 */         resCode = 412;
/* 366 */       throw new DavException("cannot copy item", resCode, se);
/*     */     }
/*     */   }
/*     */   
/*     */   public int getId() {
/* 371 */     return this.mId;
/*     */   }
/*     */   
/*     */   public ItemId getItemId() {
/* 375 */     return new ItemId(this.mOwnerId, this.mId);
/*     */   }
/*     */   
/*     */   private Map<QName, org.dom4j.Element> getDeadProps(DavContext ctxt, MailItem item) throws DocumentException, IOException, ServiceException {
/* 379 */     HashMap<QName, org.dom4j.Element> props = new HashMap();
/* 380 */     Mailbox mbox = item.getMailbox();
/* 381 */     Metadata data = mbox.getConfig(ctxt.getOperationContext(), "caldav");
/* 382 */     if (data == null)
/* 383 */       return props;
/* 384 */     String configVal = data.get(Integer.toString(item.getId()), null);
/* 385 */     if (configVal == null)
/* 386 */       return props;
/* 387 */     if (configVal.length() == 0)
/* 388 */       return props;
/* 389 */     ByteArrayInputStream in = new ByteArrayInputStream(configVal.getBytes("UTF-8"));
/* 390 */     Document doc = com.zimbra.common.soap.Element.getSAXReader().read(in);
/* 391 */     org.dom4j.Element e = doc.getRootElement();
/* 392 */     if (e == null)
/* 393 */       return props;
/* 394 */     for (Object obj : e.elements())
/* 395 */       if ((obj instanceof org.dom4j.Element)) {
/* 396 */         org.dom4j.Element elem = (org.dom4j.Element)obj;
/* 397 */         elem.detach();
/* 398 */         props.put(elem.getQName(), elem);
/*     */       }
/* 400 */     return props;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void patchProperties(DavContext ctxt, java.util.Collection<org.dom4j.Element> set, java.util.Collection<QName> remove)
/*     */     throws DavException, IOException
/*     */   {
/* 410 */     List<QName> reqProps = new ArrayList();
/* 411 */     for (QName n : remove) {
/* 412 */       this.mDeadProps.remove(n);
/* 413 */       reqProps.add(n);
/*     */     }
/* 415 */     for (org.dom4j.Element e : set) {
/* 416 */       QName name = e.getQName();
/* 417 */       if ((name.equals(DavElements.E_DISPLAYNAME)) && ((this.type == MailItem.Type.FOLDER) || (this.type == MailItem.Type.MOUNTPOINT)))
/*     */       {
/*     */         try
/*     */         {
/* 421 */           String val = e.getText();
/* 422 */           String uri = getUri();
/* 423 */           Mailbox mbox = getMailbox(ctxt);
/* 424 */           mbox.rename(ctxt.getOperationContext(), this.mId, this.type, val, this.mFolderId);
/* 425 */           setProperty("displayname", val);
/* 426 */           UrlNamespace.addToRenamedResource(getOwner(), uri, this);
/* 427 */           UrlNamespace.addToRenamedResource(getOwner(), uri.substring(0, uri.length() - 1), this);
/*     */         } catch (ServiceException se) {
/* 429 */           ctxt.getResponseProp().addPropError(DavElements.E_DISPLAYNAME, new DavException(se.getMessage(), 424));
/*     */         }
/*     */         
/* 432 */         this.mDeadProps.remove(name);
/*     */       }
/* 434 */       else if ((name.equals(DavElements.E_CALENDAR_COLOR)) && ((this.type == MailItem.Type.FOLDER) || (this.type == MailItem.Type.MOUNTPOINT)))
/*     */       {
/*     */ 
/* 437 */         String colorStr = e.getText();
/* 438 */         Color color = new Color(colorStr.substring(0, 7));
/* 439 */         byte col = (byte)COLOR_LIST.indexOf(colorStr);
/* 440 */         if (col >= 0)
/* 441 */           color.setColor(col);
/*     */         try {
/* 443 */           Mailbox mbox = getMailbox(ctxt);
/* 444 */           mbox.setColor(ctxt.getOperationContext(), new int[] { this.mId }, this.type, color);
/*     */         } catch (ServiceException se) {
/* 446 */           ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_COLOR, new DavException(se.getMessage(), 424));
/*     */         }
/*     */         
/* 449 */         this.mDeadProps.remove(name);
/*     */       }
/* 451 */       else if (name.equals(DavElements.E_SUPPORTED_CALENDAR_COMPONENT_SET))
/*     */       {
/*     */ 
/* 454 */         List<org.dom4j.Element> elements = e.elements(DavElements.E_COMP);
/* 455 */         boolean isTodo = false;
/* 456 */         boolean isEvent = false;
/* 457 */         for (org.dom4j.Element element : elements) {
/* 458 */           Attribute attr = element.attribute("name");
/* 459 */           if ((attr != null) && (CalDavProperty.CalComponent.VTODO.name().equals(attr.getValue()))) {
/* 460 */             isTodo = true;
/* 461 */           } else if ((attr != null) && (CalDavProperty.CalComponent.VEVENT.name().equals(attr.getValue()))) {
/* 462 */             isEvent = true;
/*     */           }
/*     */         }
/* 465 */         if ((isEvent ^ isTodo)) {
/* 466 */           MailItem.Type type = isEvent ? MailItem.Type.APPOINTMENT : MailItem.Type.TASK;
/*     */           try {
/* 468 */             Mailbox mbox = getMailbox(ctxt);
/* 469 */             mbox.setFolderDefaultView(ctxt.getOperationContext(), this.mId, type);
/*     */             
/*     */ 
/* 472 */             if ((this instanceof Collection)) {
/* 473 */               ((Collection)this).view = type;
/*     */             }
/*     */           } catch (ServiceException se) {
/* 476 */             ctxt.getResponseProp().addPropError(name, new DavException(se.getMessage(), 424));
/*     */           }
/*     */         } else {
/* 479 */           ctxt.getResponseProp().addPropError(name, new DavException.CannotModifyProtectedProperty(name));
/*     */         }
/*     */       }
/*     */       else {
/* 483 */         this.mDeadProps.put(name, e);
/* 484 */         reqProps.add(name);
/*     */       } }
/* 486 */     String configVal = "";
/* 487 */     if (this.mDeadProps.size() > 0) {
/* 488 */       Document doc = DocumentHelper.createDocument();
/* 489 */       org.dom4j.Element top = doc.addElement("caldav");
/* 490 */       for (Map.Entry<QName, org.dom4j.Element> entry : this.mDeadProps.entrySet()) {
/* 491 */         top.add(((org.dom4j.Element)entry.getValue()).detach());
/*     */       }
/* 493 */       ByteArrayOutputStream out = new ByteArrayOutputStream();
/* 494 */       OutputFormat format = OutputFormat.createCompactFormat();
/* 495 */       XMLWriter writer = new XMLWriter(out, format);
/* 496 */       writer.write(doc);
/* 497 */       configVal = new String(out.toByteArray(), "UTF-8");
/*     */       
/* 499 */       if (configVal.length() > 1024)
/* 500 */         for (Map.Entry<QName, org.dom4j.Element> entry : this.mDeadProps.entrySet())
/* 501 */           ctxt.getResponseProp().addPropError((QName)entry.getKey(), new DavException("prop length exceeded", 507));
/*     */     }
/* 503 */     Mailbox mbox = null;
/*     */     try {
/* 505 */       mbox = getMailbox(ctxt);
/* 506 */       mbox.lock.lock();
/* 507 */       Metadata data = mbox.getConfig(ctxt.getOperationContext(), "caldav");
/* 508 */       if (data == null) {
/* 509 */         data = new Metadata();
/*     */       }
/* 511 */       data.put(Integer.toString(this.mId), configVal);
/* 512 */       mbox.setConfig(ctxt.getOperationContext(), "caldav", data);
/*     */     } catch (ServiceException se) {
/* 514 */       for (QName qname : reqProps)
/* 515 */         ctxt.getResponseProp().addPropError(qname, new DavException(se.getMessage(), 403));
/*     */     } finally {
/* 517 */       if (mbox != null) {
/* 518 */         mbox.lock.release();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public ResourceProperty getProperty(QName prop) {
/* 524 */     ResourceProperty rp = null;
/* 525 */     if (this.mDeadProps != null) {
/* 526 */       org.dom4j.Element e = (org.dom4j.Element)this.mDeadProps.get(prop);
/* 527 */       if (e != null)
/* 528 */         rp = new ResourceProperty(e);
/*     */     }
/* 530 */     if (rp == null)
/* 531 */       rp = super.getProperty(prop);
/* 532 */     return rp;
/*     */   }
/*     */   
/*     */   public static String getEtag(MailItem item) {
/* 536 */     return getEtag(Long.toString(item.getModifiedSequence()), Long.toString(item.getSavedSequence()));
/*     */   }
/*     */   
/* 539 */   public static String getEtag(String modMetadata, String modContent) { return "\"" + modMetadata + "-" + modContent + "\""; }
/*     */   
/*     */   public void setAce(DavContext ctxt, List<Acl.Ace> aceList) throws ServiceException, DavException
/*     */   {
/* 543 */     ACL acl = new ACL();
/* 544 */     for (Acl.Ace ace : aceList) {
/* 545 */       if (ace.getRights() > 0)
/* 546 */         acl.grantAccess(ace.getZimbraId(), ace.getGranteeType(), ace.getRights(), null);
/*     */     }
/* 548 */     Mailbox mbox = getMailbox(ctxt);
/* 549 */     mbox.setPermissions(ctxt.getOperationContext(), getId(), acl);
/*     */   }
/*     */   
/*     */   public List<Acl.Ace> getAce(DavContext ctxt) throws ServiceException, DavException {
/* 553 */     ArrayList<Acl.Ace> aces = new ArrayList();
/* 554 */     Mailbox mbox = getMailbox(ctxt);
/* 555 */     MailItem item = mbox.getItemById(ctxt.getOperationContext(), this.mId, MailItem.Type.UNKNOWN);
/* 556 */     Folder f = null;
/* 557 */     if (item.getType() == MailItem.Type.FOLDER) {
/* 558 */       f = (Folder)item;
/*     */     } else
/* 560 */       f = mbox.getFolderById(ctxt.getOperationContext(), item.getParentId());
/* 561 */     ACL effectiveAcl = f.getEffectiveACL();
/* 562 */     if (effectiveAcl == null) {
/* 563 */       return aces;
/*     */     }
/* 565 */     List<ACL.Grant> grants = effectiveAcl.getGrants();
/* 566 */     if (grants == null) {
/* 567 */       return aces;
/*     */     }
/* 569 */     for (ACL.Grant g : grants) {
/* 570 */       if (g.hasGrantee())
/*     */       {
/* 572 */         aces.add(new Acl.Ace(g.getGranteeId(), g.getGrantedRights(), g.getGranteeType())); }
/*     */     }
/* 574 */     return aces;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   protected ResourceProperty getIcalColorProperty()
/*     */   {
/* 585 */     ResourceProperty color = new ResourceProperty(DavElements.E_CALENDAR_COLOR);
/* 586 */     if (this.mColor.hasMapping())
/*     */     {
/* 588 */       color.setStringValue(COLOR_MAP[this.mColor.getMappedColor()]);
/*     */     }
/*     */     else
/* 591 */       color.setStringValue(this.mColor.toString() + "FF");
/* 592 */     return color;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/resource/MailItemResource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */